package com.xxxx.mail.config;

import com.xxxx.server.pojo.Employee;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.DefaultClassMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * amqp配置.
 */
@Configuration
public class AmqpConfig {


//    @Bean
//    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
//        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
//        rabbitTemplate.setMessageConverter(jsonMessageConverter());
//        return rabbitTemplate;
//    }
//
//    @Bean
//    public Jackson2JsonMessageConverter jsonMessageConverter(){
//        Jackson2JsonMessageConverter jsonConverter = new Jackson2JsonMessageConverter();
//        jsonConverter.setClassMapper(classMapper());
//        return jsonConverter;
//    }
//
//    @Bean
//    public DefaultClassMapper classMapper(){
//        DefaultClassMapper classMapper = new DefaultClassMapper();
//        HashMap<String, Class<?>> idClassMapping = new HashMap<>();
//        idClassMapping.put("thing1", Employee.class);
//        classMapper.setIdClassMapping(idClassMapping);
//        return classMapper;
//    }




//    /**
//     * 交换机.
//     */
//    public final static String EXCHANGE = "";
//    /**
//     * hello队列.
//     */
//    public final static String HELLO = "crm.hello";
//    /**
//     * 建立订单队列.
//     */
//    public final static String LIND_GENERATE_ORDER = "crm.generate.order";


//    @Bean
//    public MessageConverter messageConverter(){
//        return new Jackson2JsonMessageConverter();
//    }
//    /**
//     * 绑定exchange & queue & routekey.
//     *
//     * @param queueMessage 队列
//     * @param exchange     交换机
//     * @param routekey     路由
//     * @return
//     */
//    public Binding bindingExchange(Queue queueMessage, TopicExchange exchange, String routekey) {
//        return BindingBuilder.bind(queueMessage).to(exchange).with(routekey);
//    }


//    /**
//     * rabbitMq里初始化exchange.
//     *
//     * @return
//     */
//    @Bean
//    public TopicExchange crmExchange() {
//        return new TopicExchange(EXCHANGE);
//    }

//    /**
//     * rabbitMq里初始化队列crm.hello.
//     *
//     * @return
//     */
//    @Bean
//    public Queue helloQueue() {
//        return new Queue(HELLO);
//    }
//
//    /**
//     * rabbitMq里初始化队列crm.generate.order.
//     *
//     * @return
//     */
//    @Bean
//    public Queue orderQueue() {
//        return new Queue(LIND_GENERATE_ORDER);
//    }

//    @Bean
//    public Queue queue(){
//        return new Queue("mail.welcome");
//    }

}
